package com.tj.collection.controller.lending.response;

import com.fqgj.common.api.ResponseData;
import com.fqgj.common.utils.CollectionUtils;
import com.fqgj.common.utils.DateUtil;
import com.fqgj.common.utils.TimeUtils;
import com.tj.collection.db.entity.ClCommentEntity;
import com.tj.collection.db.entity.ClPhoneRecordEntity;
import com.tj.collection.service.request.ClSmsInputVo;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: pavan
 * Date: 2019/9/11
 * Time: 下午1:34
 */
public class ClCommentResponse implements ResponseData {

    private List<Item> collectionCommentList;

    private List<PrItem> phoneRecordList;

    private List<Item2> smsList;

    public ClCommentResponse(List<ClCommentEntity> clCommentEntityList, List<ClPhoneRecordEntity> clPhoneRecordEntityList, List<ClSmsInputVo> smsList) {
        clCommentEntityList.sort((o1, o2) -> {
            return o2.getGmtCreate().compareTo(o1.getGmtCreate());
        });

        clPhoneRecordEntityList.sort((o1, o2) -> {
            return o2.getGmtCreate().compareTo(o1.getGmtCreate());
        });

        this.collectionCommentList = new ArrayList<>();
        for (ClCommentEntity clCommentEntity : clCommentEntityList) {
            Item item = new Item();
            item.setFollowId(clCommentEntity.getFollowId());
            item.setFollowUp(clCommentEntity.getFollowUp());
            item.setGmtCreate(DateUtil.getDate(clCommentEntity.getGmtCreate(), "yyyy-MM-dd HH:mm:ss"));
            item.setType(clCommentEntity.getType());
            item.setMobile(clCommentEntity.getMobile());
            item.setContent(clCommentEntity.getContent());
            this.collectionCommentList.add(item);
        }

        this.phoneRecordList = new ArrayList<>();
        for (ClPhoneRecordEntity entity : clPhoneRecordEntityList) {
            PrItem prItem = new PrItem();
            BeanUtils.copyProperties(entity, prItem);
            this.phoneRecordList.add(prItem);
        }
        this.smsList = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(smsList)) {
            for (ClSmsInputVo vo : smsList) {
                Item2 item2 = new Item2();
                item2.setName(vo.getName());
                item2.setMobile(vo.getMobile());
                item2.setContent(vo.getContent());
                item2.setSendTime(DateUtil.getDate(new Date(vo.getSendTime()), "yyyy-MM-dd HH:mm:ss"));
                this.smsList.add(item2);
            }
        }
    }

    private static class Item {
        /**
         * 跟进人
         */
        private Integer followId;
        /**
         * 跟进人
         */
        private String followUp;
        /**
         * 时间
         */
        private String gmtCreate;
        /**
         * 类型 0-标签记录 1-电话催记
         */
        private Integer type;
        /**
         * 电话号码
         */
        private String mobile;
        /**
         * 内容
         */
        private String content;

        public Integer getFollowId() {
            return followId;
        }

        public Item setFollowId(Integer followId) {
            this.followId = followId;
            return this;
        }

        public String getFollowUp() {
            return followUp;
        }

        public Item setFollowUp(String followUp) {
            this.followUp = followUp;
            return this;
        }

        public String getGmtCreate() {
            return gmtCreate;
        }

        public Item setGmtCreate(String gmtCreate) {
            this.gmtCreate = gmtCreate;
            return this;
        }

        public Integer getType() {
            return type;
        }

        public Item setType(Integer type) {
            this.type = type;
            return this;
        }

        public String getMobile() {
            return mobile;
        }

        public Item setMobile(String mobile) {
            this.mobile = mobile;
            return this;
        }

        public String getContent() {
            return content;
        }

        public Item setContent(String content) {
            this.content = content;
            return this;
        }
    }

    private static class PrItem {
        /**
         * 跟进人
         */
        private Integer followId;
        /**
         * 跟进人
         */
        private String followUp;
        /**
         * 时间
         */
        private Date gmtCreate;
        /**
         * 联系人名字/昵称
         */
        private String name;
        /**
         * 电话号码
         */
        private String mobile;
        /**
         * 通话结果
         */
        private String callingResult;
        /**
         * 关系
         */
        private String relation;
        /**
         * 内容
         */
        private String content;

        public Integer getFollowId() {
            return followId;
        }

        public PrItem setFollowId(Integer followId) {
            this.followId = followId;
            return this;
        }

        public String getFollowUp() {
            return followUp;
        }

        public PrItem setFollowUp(String followUp) {
            this.followUp = followUp;
            return this;
        }

        public String getName() {
            return name;
        }

        public PrItem setName(String name) {
            this.name = name;
            return this;
        }

        public String getMobile() {
            return mobile;
        }

        public PrItem setMobile(String mobile) {
            this.mobile = mobile;
            return this;
        }

        public Date getGmtCreate() {
            return gmtCreate;
        }

        public PrItem setGmtCreate(Date gmtCreate) {
            this.gmtCreate = gmtCreate;
            return this;
        }

        public String getCallingResult() {
            return callingResult;
        }

        public PrItem setCallingResult(String callingResult) {
            this.callingResult = callingResult;
            return this;
        }

        public String getRelation() {
            return relation;
        }

        public PrItem setRelation(String relation) {
            this.relation = relation;
            return this;
        }

        public String getContent() {
            return content;
        }

        public PrItem setContent(String content) {
            this.content = content;
            return this;
        }
    }

    private static class Item2 {
        /**
         * 姓名
         */
        private String name;
        /**
         * 手机号
         */
        private String mobile;
        /**
         * 文案
         */
        private String content;
        /**
         * 短信发送时间戳
         */
        private String sendTime;

        public String getName() {
            return name;
        }

        public Item2 setName(String name) {
            this.name = name;
            return this;
        }

        public String getMobile() {
            return mobile;
        }

        public Item2 setMobile(String mobile) {
            this.mobile = mobile;
            return this;
        }

        public String getContent() {
            return content;
        }

        public Item2 setContent(String content) {
            this.content = content;
            return this;
        }

        public String getSendTime() {
            return sendTime;
        }

        public Item2 setSendTime(String sendTime) {
            this.sendTime = sendTime;
            return this;
        }
    }
}
